package Stage;

import DataProcess.*;
import baseAPI.AlertStage;
import baseAPI.Animation;
import baseAPI.Database;
import baseAPI.MyServer;
import baseClass.Admin;
import baseClass.History;
import baseClass.Room;
import baseClass.RoomStatistics;
import com.github.wxpay.sdk.Order;
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Insets;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.chart.PieChart;
import javafx.scene.control.*;
import javafx.scene.effect.DropShadow;
import javafx.scene.effect.Effect;
import javafx.scene.effect.Lighting;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCode;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.paint.ImagePattern;
import javafx.scene.shape.ArcType;
import javafx.scene.text.Text;
import javafx.stage.Modality;
import javafx.stage.Stage;

import java.awt.event.KeyEvent;
import java.io.IOException;
import javafx.scene.control.ToggleButton;
import javafx.stage.WindowEvent;
import sun.misc.Version;

import static java.awt.event.KeyEvent.*;


public class Stage1 extends Application {
    ObservableList<String> clients = FXCollections.observableArrayList();
    ListView<String> clientListView;
    public static Database database;

    private boolean isManager =false;

/*页面处理*/
    //五个页面的对象
    Parent mainPage, history, service, vipInfo, checkInAndOut;
    private ToggleButton btnCheckInAndOut;
    private ToggleButton btnHistory;
    private ToggleButton btnService;
    private ToggleButton btnVipInfo;
    private ToggleButton btnMainPage;
    private Hyperlink logIn;
    private Admin admin;
    private BorderPane borderPane;
    private Button btnChangePrice;
    private static Canvas canvas;
    private Label labelPriceSingle;
    private Label labelPriceDouble;
    private Label labelPriceFamily;
    private Label labelPriceCouple;
    private Label labelPriceLuxury;
    private Label labelPricePresident;
    private MyServer server;
    private RoomStatistics roomStatisticsRoomStatistics;
    private int selected = 1;//当前选中的按钮编号

    private static Label labelSingle;
    private static Label labelDouble;
    private static Label labelFamily;
    private static Label labelCouple;
    private static Label labelLuxury;
    private static Label labelPresident;
    private static GraphicsContext gcSingle;
    private static GraphicsContext gcDouble;
    private static GraphicsContext gcFamily;
    private static GraphicsContext gcCouple;
    private static GraphicsContext gcLuxury;
    private static GraphicsContext gcPresident;


    @Override
    public void start(Stage primaryStage) throws Exception{
        Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
   //     database = new Database("192.168.43.197", "ihms", "xjh", "123456");
       database = new Database("localhost", "ihms", "root", "123456");
        server = new MyServer();
        new Thread(server).start();
        //预加载五个页面
        mainPage = FXMLLoader.load(getClass().getResource("mainPage.fxml"));
        history = FXMLLoader.load(getClass().getResource("history.fxml"));
        service = FXMLLoader.load(getClass().getResource("service.fxml"));
        vipInfo = FXMLLoader.load(getClass().getResource("vipInfo.fxml"));
        checkInAndOut = FXMLLoader.load(getClass().getResource("checkInAndOut.fxml"));

        //五个页面的控件事件绑定
        MainPage.bind(mainPage, database);
        HistoryPage.bind(history, database);
        ServicePage.bind(service, database, server);
        VipInfoPage.bind(vipInfo, database);
        CheckInAndOutPage.bind(checkInAndOut, database, server);

        MainPage.updateMainPage(mainPage);
/*id匹配*/
        AnchorPane anchorPane = (AnchorPane)root.lookup("#anchorpane");
        borderPane = (BorderPane)root.lookup("#borderpane");
        Label labelSign = (Label)root.lookup("#labelsign");
        Label stateBar = (Label)root.lookup("#statebar");
        Pane roomStatistics = (Pane)root.lookup("#labelroom");
        Label topBar = (Label)root.lookup("#topBar");
        logIn = (Hyperlink)root.lookup("#hyperlink");
        canvas = (Canvas) root.lookup("#canvas");
        btnCheckInAndOut = (ToggleButton)root.lookup("#btn1");
        btnHistory = (ToggleButton)root.lookup("#btn2");
        btnService = (ToggleButton)root.lookup("#btn3");
        btnVipInfo = (ToggleButton)root.lookup("#btn4");
        btnMainPage = (ToggleButton)root.lookup("#btn5");
        labelPriceSingle = (Label)root.lookup(("#labelPriceSingle"));
        labelPriceDouble = (Label)root.lookup("#labelPriceDouble");
        labelPriceFamily = (Label)root.lookup("#labelPriceFamily");
        labelPriceCouple = (Label)root.lookup("#labelPriceCouple");
        labelPriceLuxury = (Label)root.lookup("#labelPriceLuxury");
        labelPricePresident = (Label)root.lookup("#labelPricePresident");
        btnChangePrice = (Button)root.lookup("#btnChangePrice");

        ToggleGroup toggleGroup = new ToggleGroup();
        btnMainPage.setToggleGroup(toggleGroup);
        btnCheckInAndOut.setToggleGroup(toggleGroup);
        btnHistory.setToggleGroup(toggleGroup);
        btnService.setToggleGroup(toggleGroup);
        btnVipInfo.setToggleGroup(toggleGroup);

/*杂七杂八的东西*/
        roomStatisticsRoomStatistics = new RoomStatistics(database);
        labelSign.setStyle("-fx-background-image: url('/pic/labelsign.png');-fx-border-radius: 20px;-fx-background-radius: 20px;-fx-opacity: 0.8");
        anchorPane.setStyle("-fx-background-color:rgb(20,23,34)");
        btnMainPage.setSelected(true);
        borderPane.setCenter(mainPage);
        btnMainPage.setDisable(true);
        btnChangePrice.setDisable(true);

        stateBar.setText("Version: 11.45.14  ");

        logIn.setOnAction(new EventHandler<ActionEvent>() {
            public void handle(ActionEvent event) {
                if(logIn.getText().equals("登录")) login();
                else logout();
            }
        });
        selected = 1;


/*按钮的移动动画*/
        btnCheckInAndOut.setOnMouseEntered(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                if(btnCheckInAndOut.isSelected() == false) Animation.fadeInLeft(btnCheckInAndOut);

            }
        });//移动到按钮上，按钮右移突出
        btnCheckInAndOut.setOnMouseExited(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                if(btnCheckInAndOut.isSelected() == false)Animation.reset(btnCheckInAndOut);
            }
        });//离开按钮，按钮复原

        btnHistory.setOnMouseEntered(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                if(btnHistory.isSelected() == false) Animation.fadeInLeft(btnHistory);
            }
        });//移动到按钮上，按钮右移突出
        btnHistory.setOnMouseExited(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                if(btnHistory.isSelected() == false) Animation.reset(btnHistory);
            }
        });//离开按钮，按钮复原

        btnService.setOnMouseEntered(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                if(btnService.isSelected() == false) Animation.fadeInLeft(btnService);
            }
        });//移动到按钮上，按钮右移突出
        btnService.setOnMouseExited(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                if(btnService.isSelected() == false) Animation.reset(btnService);
            }
        });//离开按钮，按钮复原

        btnVipInfo.setOnMouseEntered(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                if(btnVipInfo.isSelected() == false) Animation.fadeInLeft(btnVipInfo);
            }
        });//移动到按钮上，按钮右移突出
        btnVipInfo.setOnMouseExited(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                if(btnVipInfo.isSelected() == false) Animation.reset(btnVipInfo);
            }
        });//离开按钮，按钮复原

        btnMainPage.setOnMouseEntered(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                if(btnMainPage.isSelected() == false) Animation.fadeInLeft(btnMainPage);
            }
        });//移动到按钮上，按钮右移突出
        btnMainPage.setOnMouseExited(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                if(btnMainPage.isSelected() == false) Animation.reset(btnMainPage);
            }
        });//离开按钮，按钮复原

/*页面切换*/
        btnMainPage.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                 selected = 1;
                 Animation.fadeOut(borderPane);
                 MainPage.updateMainPage(mainPage);//页面刷新
                 borderPane.setCenter(mainPage);
                 Animation.fadeIn(borderPane);
                 isBtnSelected(btnMainPage,btnCheckInAndOut,btnHistory,btnService,btnVipInfo);
            }
        });

        btnHistory.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                if(selected == 1) {
                    MainPage.stopPlay();
                    selected = 2;
                }
                Animation.fadeOut(borderPane);
                HistoryPage.updateHistory(history);//页面刷新
                borderPane.setCenter(history);
                Animation.fadeIn(borderPane);
                isBtnSelected(btnHistory,btnMainPage,btnCheckInAndOut,btnService,btnVipInfo);
            }
        });

        btnService.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                if(selected == 1) {
                    MainPage.stopPlay();
                    selected = 3;
                }
                Animation.fadeOut(borderPane);
                ServicePage.updateService(service);//页面刷新
                borderPane.setCenter(service);
                Animation.fadeIn(borderPane);
                isBtnSelected(btnService,btnMainPage,btnCheckInAndOut,btnHistory,btnVipInfo);
            }
        });

        btnVipInfo.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                if(selected == 1) {
                    MainPage.stopPlay();
                    selected = 4;
                }
                Animation.fadeOut(borderPane);
                borderPane.setCenter(vipInfo);
                Animation.fadeIn(borderPane);
                isBtnSelected(btnVipInfo,btnMainPage,btnCheckInAndOut,btnHistory,btnService);
            }
        });

        btnCheckInAndOut.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                if(selected == 1) {
                    MainPage.stopPlay();
                    selected = 5;
                }
                Animation.fadeOut(borderPane);
                CheckInAndOutPage.updateCheckInAndOut(checkInAndOut);//页面刷新
                borderPane.setCenter(checkInAndOut);
                Animation.fadeIn(borderPane);
                isBtnSelected(btnCheckInAndOut,btnMainPage,btnHistory,btnService,btnVipInfo);

            }
        });

        btnChangePrice.setOnMouseClicked(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                MainPage.stopPlay();
                changePrice();
            }
        });
/*酒店入住统计*/

        labelSingle = (Label)root.lookup("#labelSingle");
        labelDouble = (Label)root.lookup("#labelDouble");
        labelFamily = (Label)root.lookup("#labelFamily");
        labelCouple = (Label)root.lookup("#labelCouple");
        labelLuxury = (Label)root.lookup("#labelLuxury");
        labelPresident = (Label)root.lookup("#labelPresident");

        roomStatistics.setStyle("-fx-background-image: url('/pic/Canvas.png')");

        primaryStage.setTitle("IHMS");
        primaryStage.getIcons().add(new Image("/pic/ico.png"));
        primaryStage.setResizable(false);
        primaryStage.setScene(new Scene(root, 1600, 900));

        update();
        primaryStage.show();
    }

    public void isBtnSelected(ToggleButton b1,ToggleButton b2,ToggleButton b3,ToggleButton b4,ToggleButton b5)
    {
            b2.setLayoutX(0);
            b3.setLayoutX(0);
            b4.setLayoutX(0);
            b5.setLayoutX(0);

            b1.setDisable(true);
            b2.setDisable(false);
            b3.setDisable(false);
            b4.setDisable(false);
            b5.setDisable(false);



    }//按键选中后就不能通过点击取消，只能切换界面,点击后其他的回到原点

    public static void PresidentChange(int all,int left)
    {
        gcPresident = canvas.getGraphicsContext2D();
        gcPresident.setLineWidth(7);//总统
        gcPresident.setStroke(Color.rgb(79,204,200));
        gcPresident.strokeArc(120, 110,20,20,150,360*left/all, ArcType.OPEN);
        labelPresident.setText(left+"间");
    }

    public static void LuxuryChange(int all,int left)
    {
        gcLuxury = canvas.getGraphicsContext2D();
        gcLuxury.setLineWidth(7);//豪华
        gcLuxury.setStroke(Color.rgb(105,204,79));
        gcLuxury.strokeArc(100,90,60,60,120,360*left/all, ArcType.OPEN);
        labelLuxury.setText(left+"间");
    }

    public static void SingleChange(int all,int left)
    {
        gcSingle = canvas.getGraphicsContext2D();
        gcSingle.setLineWidth(7);//单人
        gcSingle.setStroke(Color.rgb(69,101,224));
        gcSingle.strokeArc(80,70,100,100,90,360*left/all, ArcType.OPEN);
        labelSingle.setText(left+"间");
    }

    public static void DoubleChange(int all,int left)
    {
        gcDouble = canvas.getGraphicsContext2D();
        gcDouble.setLineWidth(7);//双人
        gcDouble.setStroke(Color.rgb(141,79,204));
        gcDouble.strokeArc(60,50,140,140,30,360*left/all, ArcType.OPEN);
        labelDouble.setText(left+"间");
    }

    public static void CoupleChange(int all,int left)
    {
        gcCouple = canvas.getGraphicsContext2D();
        gcCouple.setLineWidth(7);//情侣
        gcCouple.setStroke(Color.rgb(204,200,79));
        gcCouple.strokeArc(20, 10,220,220,0,360*left/all, ArcType.OPEN);
        labelCouple.setText(left+"间");
    }

    public static void FamilyChange(int all,int left)
    {
        gcFamily = canvas.getGraphicsContext2D();
        gcFamily.setLineWidth(7);//亲子
        gcFamily.setStroke(Color.rgb(204,79,179));
        gcFamily.strokeArc(40,30,180,180,60,360*left/all, ArcType.OPEN);
        labelFamily.setText(left+"间");
    }

    public void login() {//管理员登录
        Stage stage = new Stage();
        stage.initModality(Modality.APPLICATION_MODAL);
        stage.getIcons().add(new Image("/pic/ico.png"));
        stage.setTitle("管理员登录");
        stage.setResizable(false);
        stage.setWidth(400);
        stage.setHeight(595);

        TextField managerIdField = new TextField();
        PasswordField passwordField = new PasswordField();
        Button check = new Button();

        DropShadow dropShadow = new DropShadow();
        dropShadow.setOffsetY(1.0);
        dropShadow.setOffsetX(1.0);
        dropShadow.setColor(Color.rgb(129,192,212));
        dropShadow.setSpread(0.2);

        managerIdField.setLayoutX(100);
        managerIdField.setLayoutY(185);
        managerIdField.setPrefWidth(250);
        managerIdField.setPrefHeight(50);
        managerIdField.setStyle(
                "    -fx-text-fill:white;\n" +
                "    -fx-opacity: 0.7;\n" +
                "    -fx-font-size: 16pt;\n" +
                "    -fx-font-family: \"MV Boli\";\n" +
                "    -fx-font-weight: bold;\n" +
                "    -fx-border-radius: 15px;\n" +
                "    -fx-background-radius: 15px;\n" +
                "    -fx-background-color: rgb(20,23,34);\n");
        managerIdField.setEffect(dropShadow);

        passwordField.setLayoutX(100);
        passwordField.setLayoutY(255);
        passwordField.setPrefWidth(250);
        passwordField.setPrefHeight(50);
        passwordField.setStyle(
                "    -fx-text-fill:white;\n" +
                "    -fx-font-size: 16pt;\n" +
                "    -fx-opacity: 0.7;\n" +
                "    -fx-font-family: \"MV Boli\";\n" +
                "    -fx-font-weight: bold;\n" +
                "    -fx-border-radius: 15px;\n" +
                "    -fx-background-radius: 15px;\n" +
                "    -fx-background-color: rgb(20,23,34);");
        passwordField.setEffect(dropShadow);


        check.setLayoutX(170);
        check.setLayoutY(340);
        check.setPrefWidth(60);
        check.setPrefHeight(60);
        check.setStyle("-fx-background-image:url(/pic/check.png);-fx-background-color: transparent;");

        check.setOnMouseEntered(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                Animation.checkButton(check);
            }
        });
        check.setOnMouseExited(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                Animation.resetCheck(check);
            }
        });
        check.setOnMousePressed(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                Animation.checked(check);
            }
        });
        check.setOnMouseReleased(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                Animation.reset1(check);
            }
        });
        check.setOnMouseClicked(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                String userName = managerIdField.getText();
                String psw = passwordField.getText();
                admin = new Admin(userName, psw);

                if(admin.check(database))
                {

                    if(admin.getPower(database)==1)
                    {
                        btnChangePrice.setDisable(false);
                    }
                    else
                    {
                        btnChangePrice.setDisable(true);
                    }
                    isManager = true;
                    update();
                    stage.close();
                }
                else
                {
                    AlertStage.show("提示", "账号或密码有误");
                    managerIdField.setText("");
                    passwordField.setText("");
                    managerIdField.requestFocus();
                }
            }
        });

        managerIdField.setOnKeyPressed(new EventHandler<javafx.scene.input.KeyEvent>() {
            @Override
            public void handle(javafx.scene.input.KeyEvent event) {
                if(event.getCode() == KeyCode.ENTER)
                {
                    passwordField.requestFocus();
                }
            }
        });

        passwordField.setOnKeyPressed(new EventHandler<javafx.scene.input.KeyEvent>() {
            @Override
            public void handle(javafx.scene.input.KeyEvent event) {
                if(event.getCode() == KeyCode.ENTER)
                {
                    Animation.checked(check);
                    String userName = managerIdField.getText();
                    String psw = passwordField.getText();
                    admin = new Admin(userName, psw);

                    if(admin.check(database))
                    {

                        if(admin.getPower(database)==1)
                        {
                            btnChangePrice.setDisable(false);
                        }
                        else
                        {
                            btnChangePrice.setDisable(true);
                        }
                        isManager = true;
                        update();
                        stage.close();
                    }
                    else
                    {
                        Animation.reset1(check);
                        AlertStage.show("提示", "账号或密码有误");
                        managerIdField.setText("");
                        passwordField.setText("");
                        managerIdField.requestFocus();
                    }

                }
            }
        });

        Pane pane = new Pane(managerIdField, passwordField, check);
        pane.setStyle("-fx-background-image: url(/pic/login.png)");
        Scene scene = new Scene(pane);
        stage.setScene(scene);
        stage.show();
    }

    public static void cleanGraph()
    {
        GraphicsContext gcClean = canvas.getGraphicsContext2D();
        gcClean.clearRect(0,0,260,260);
    }
    public void update()
    {
        if(isManager==false)
        {
            logIn.setText("登录");
            btnCheckInAndOut.setDisable(true);
            btnMainPage.setDisable(true);
            btnHistory.setDisable(true);
            btnService.setDisable(true);
            btnVipInfo.setDisable(true);
        }
        else
        {
            logIn.setText("登出");
            btnCheckInAndOut.setDisable(false);
            btnMainPage.setDisable(true);
            btnHistory.setDisable(false);
            btnService.setDisable(false);
            btnVipInfo.setDisable(false);
        }

        labelPriceSingle.setText(String.valueOf(Room.getPrice(Room.SINGLE,database)));
        labelPriceDouble.setText(String.valueOf(Room.getPrice(Room.DOUBLE,database)));
        labelPriceFamily.setText(String.valueOf(Room.getPrice(Room.FAMILY,database)));
        labelPriceCouple.setText(String.valueOf(Room.getPrice(Room.COUPLE,database)));
        labelPriceLuxury.setText(String.valueOf(Room.getPrice(Room.LUXURY,database)));
        labelPricePresident.setText(String.valueOf(Room.getPrice(Room.PRESIDENT,database)));

        roomStatisticsRoomStatistics.inquire(Room.PRESIDENT);
        PresidentChange(roomStatisticsRoomStatistics.getRoomsTotal(), roomStatisticsRoomStatistics.getRoomsLeft());
        roomStatisticsRoomStatistics.inquire(Room.LUXURY);
        LuxuryChange(roomStatisticsRoomStatistics.getRoomsTotal(), roomStatisticsRoomStatistics.getRoomsLeft());
        roomStatisticsRoomStatistics.inquire(Room.COUPLE);
        CoupleChange(roomStatisticsRoomStatistics.getRoomsTotal(), roomStatisticsRoomStatistics.getRoomsLeft());
        roomStatisticsRoomStatistics.inquire(Room.DOUBLE);
        DoubleChange(roomStatisticsRoomStatistics.getRoomsTotal(), roomStatisticsRoomStatistics.getRoomsLeft());
        roomStatisticsRoomStatistics.inquire(Room.SINGLE);
        SingleChange(roomStatisticsRoomStatistics.getRoomsTotal(), roomStatisticsRoomStatistics.getRoomsLeft());
        roomStatisticsRoomStatistics.inquire(Room.FAMILY);
        FamilyChange(roomStatisticsRoomStatistics.getRoomsTotal(), roomStatisticsRoomStatistics.getRoomsLeft());
    }


    public void changePrice()
    {
        Stage stage = new Stage();
        stage.initModality(Modality.APPLICATION_MODAL);
        stage.getIcons().add(new Image("/pic/ico.png"));
        stage.setTitle("价格修改");
        stage.setResizable(false);
        stage.setWidth(400);
        stage.setHeight(595);

        ChoiceBox<String> roomKind = new ChoiceBox();
        TextField priceField = new TextField();
        Button check = new Button();
        int[] type = new int[]{Room.SINGLE,Room.DOUBLE,Room.FAMILY,Room.COUPLE,Room.LUXURY,Room.PRESIDENT};
        roomKind.setItems(FXCollections.observableArrayList("单人间","双人间","亲子间","情侣间","豪华套房","总统套房"));


        DropShadow dropShadow = new DropShadow();
        dropShadow.setOffsetY(1.0);
        dropShadow.setOffsetX(1.0);
        dropShadow.setColor(Color.rgb(129,192,212));
        dropShadow.setSpread(0.2);

        roomKind.setLayoutX(100);
        roomKind.setLayoutY(185);
        roomKind.setPrefWidth(250);
        roomKind.setPrefHeight(50);
        roomKind.setStyle(
                        "    -fx-opacity: 0.7;\n" +
                        "    -fx-font-size: 16pt;\n" +
                        "    -fx-font-family: \"MV Boli\";\n" +
                        "    -fx-font-weight: bold;\n" +
                        "    -fx-border-radius: 15px;\n" +
                        "    -fx-background-radius: 15px;\n" +
                        "    -fx-background-color: rgb(151,178,255);\n");
        roomKind.setEffect(dropShadow);

        priceField.setLayoutX(100);
        priceField.setLayoutY(255);
        priceField.setPrefWidth(250);
        priceField.setPrefHeight(50);
        priceField.setStyle(
                "    -fx-text-fill:white;\n" +
                        "    -fx-font-size: 16pt;\n" +
                        "    -fx-opacity: 0.7;\n" +
                        "    -fx-font-family: \"MV Boli\";\n" +
                        "    -fx-font-weight: bold;\n" +
                        "    -fx-border-radius: 15px;\n" +
                        "    -fx-background-radius: 15px;\n" +
                        "    -fx-background-color: rgb(151,178,255);");
        priceField.setEffect(dropShadow);

        check.setLayoutX(170);
        check.setLayoutY(340);
        check.setPrefWidth(60);
        check.setPrefHeight(60);
        check.setStyle("-fx-background-image:url(/pic/check.png);-fx-background-color: transparent;");

        check.setOnMouseEntered(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                Animation.checkButton(check);
            }
        });
        check.setOnMouseExited(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                Animation.resetCheck(check);
            }
        });
        check.setOnMousePressed(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                Animation.checked(check);
            }
        });
        check.setOnMouseReleased(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                Animation.reset1(check);
            }
        });
        check.setOnMouseClicked(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                //修改价格成功
                boolean f = true;
                if(roomKind.getSelectionModel().isEmpty()) AlertStage.show("提示","请选择房间类型！");
                else{
                try{
                    Integer.parseInt(priceField.getText());
                }
                catch (NumberFormatException ex)
                {
                    AlertStage.show("提示","请输入要修改的价格");
                    f = false;
                }
                }
                if(f==true) {
                    int i = roomKind.getSelectionModel().getSelectedIndex()+1;
                    switch (i) {
                        case 1:
                            labelPriceSingle.setText(priceField.getText());
                            Room.setPrice(Room.SINGLE,Integer.parseInt(priceField.getText()),database);
                            break;
                        case 2:
                            labelPriceDouble.setText(priceField.getText());
                            Room.setPrice(Room.DOUBLE,Integer.parseInt(priceField.getText()),database);
                            break;
                        case 3:
                            labelPriceFamily.setText(priceField.getText());
                            Room.setPrice(Room.FAMILY,Integer.parseInt(priceField.getText()),database);
                            break;
                        case 4:
                            labelPriceCouple.setText(priceField.getText());
                            Room.setPrice(Room.COUPLE,Integer.parseInt(priceField.getText()),database);
                            break;
                        case 5:
                            labelPriceLuxury.setText(priceField.getText());
                            Room.setPrice(Room.LUXURY,Integer.parseInt(priceField.getText()),database);
                            break;
                        case 6:
                            labelPricePresident.setText(priceField.getText());
                            Room.setPrice(Room.PRESIDENT,Integer.parseInt(priceField.getText()),database);
                            break;
                    }
                    MainPage.updateMainPage(mainPage);
                    stage.close();
                }
            }
        });

        priceField.setOnKeyPressed(new EventHandler<javafx.scene.input.KeyEvent>() {
            @Override
            public void handle(javafx.scene.input.KeyEvent event) {
                if(event.getCode() == KeyCode.ENTER)
                {
                    Animation.checked(check);
                    boolean f = true;
                    if(roomKind.getSelectionModel().isEmpty()) AlertStage.show("提示","请选择房间类型！");
                    else{
                        try{
                            Integer.parseInt(priceField.getText());
                        }
                        catch (NumberFormatException ex)
                        {
                            Animation.reset1(check);
                            AlertStage.show("提示","请输入要修改的价格");
                            f = false;
                        }
                    }
                    if(f==true) {
                        int i = roomKind.getSelectionModel().getSelectedIndex()+1;
                        switch (i) {
                            case 1:
                                labelPriceSingle.setText(priceField.getText());
                                Room.setPrice(Room.SINGLE,Integer.parseInt(priceField.getText()),database);
                                break;
                            case 2:
                                labelPriceDouble.setText(priceField.getText());
                                Room.setPrice(Room.DOUBLE,Integer.parseInt(priceField.getText()),database);
                                break;
                            case 3:
                                labelPriceFamily.setText(priceField.getText());
                                Room.setPrice(Room.FAMILY,Integer.parseInt(priceField.getText()),database);
                                break;
                            case 4:
                                labelPriceCouple.setText(priceField.getText());
                                Room.setPrice(Room.COUPLE,Integer.parseInt(priceField.getText()),database);
                                break;
                            case 5:
                                labelPriceLuxury.setText(priceField.getText());
                                Room.setPrice(Room.LUXURY,Integer.parseInt(priceField.getText()),database);
                                break;
                            case 6:
                                labelPricePresident.setText(priceField.getText());
                                Room.setPrice(Room.PRESIDENT,Integer.parseInt(priceField.getText()),database);
                                break;
                        }
                        MainPage.updateMainPage(mainPage);
                        stage.close();
                    }
                }
            }
        });

        stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
            @Override
            public void handle(WindowEvent event) {
                MainPage.updateMainPage(mainPage);
            }
        });

        Pane pane = new Pane(roomKind,priceField, check);
        pane.setStyle("-fx-background-image: url(/pic/priceChange.png)");
        Scene scene = new Scene(pane);
        stage.setScene(scene);
        stage.show();
    }

    public void logout()
    {
        selected = 1;
        Animation.fadeOut(borderPane);
        MainPage.updateMainPage(mainPage);//页面刷新
        borderPane.setCenter(mainPage);
        Animation.fadeIn(borderPane);


        btnMainPage.setSelected(true);
        isBtnSelected(btnMainPage,btnCheckInAndOut,btnHistory,btnService,btnVipInfo);
        Animation.fadeInLeft(btnMainPage);

        isManager = false;
        btnChangePrice.setDisable(true);
        update();
    }
}

